package offer.easy;

public class CatMinNumber {

    public static String catMinNumber(int[] array) {
        if (array == null || array.length == 0) {
            return null;
        }

        String temp = "";
        String[] strings = new String[array.length];
        for (int i = 0; i < array.length; i++) {
            strings[i] = array[i] + "";
        }

        for (int i = 0; i < strings.length; i++) {
            for (int j = 0; j < strings.length - 1 - i; j++) {
                if ((strings[j]+strings[j+1]).compareTo((strings[j+1]+strings[j]))>0) {
                //(Integer.valueOf(strings[j]+strings[j+1]) > Integer.valueOf(strings[j+1]+strings[j])) {
                    temp = strings[j];
                    strings[j] = strings[j+1];
                    strings[j+1] = temp;
                }
            }
        }

        temp = "";
        for (String str:strings){
            temp = temp + str;
        }
        return temp;
    }

    public static void main(String[] args) {
        int[] array = {3334,3,3333332};
        String result = catMinNumber(array);
        System.out.println(result);
    }
}
